package com.zprmb.udzt.adapter;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;

import android.content.Context;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.AbsoluteSizeSpan;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zprmb.udzt.R;
import com.zprmb.udzt.bean.JiLu_Bean;
import com.zprmb.udzt.util.TimeUtils;

public class ALLJiluAdapter extends BaseAdapter{

	private Context context;
	private ArrayList<JiLu_Bean> list;
	private DecimalFormat df3 = new DecimalFormat("###");
	
	
	public ALLJiluAdapter(Context context,ArrayList<JiLu_Bean> list){
		this.context = context;
		this.list = list;
	}
	
	public int getCount() {
		return list.size();
	}

	public Object getItem(int arg0) {
		return arg0;
	}

	public long getItemId(int arg0) {
		return arg0;
	}

	public View getView(int position, View convertView, ViewGroup arg2) {
		JiLu_Bean jb = list.get(position);
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = View.inflate(context, R.layout.v4_item_alljilu, null);
			holder.tv_v4_item_alljilu_name = (TextView) convertView.findViewById(R.id.tv_v4_item_alljilu_name);
			holder.tv_v4_item_alljilu_time = (TextView) convertView.findViewById(R.id.tv_v4_item_alljilu_time);
			holder.tv_v4_item_alljilu_money = (TextView) convertView.findViewById(R.id.tv_v4_item_alljilu_money);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		SpannableString spanText = new SpannableString(TimeUtils.formatAllTime(new Date(Long.parseLong(jb.submitTime))));
		spanText.setSpan(new ForegroundColorSpan(Color.parseColor("#666666")), 10, spanText.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
		spanText.setSpan(new AbsoluteSizeSpan(10, true) , 10, spanText.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
		
		holder.tv_v4_item_alljilu_name.setText(jb.userName);
		holder.tv_v4_item_alljilu_money.setText(df3.format(Double.parseDouble(jb.amount)));
		holder.tv_v4_item_alljilu_time.setText(spanText.toString().substring(0, 10)+"\n"+spanText.toString().substring(10, spanText.length()));
		return convertView;
	}

	public class ViewHolder {
		TextView tv_v4_item_alljilu_name;
		TextView tv_v4_item_alljilu_time;
		TextView tv_v4_item_alljilu_money;
	}
	
}
